<include file="../header" />
<body>
<div class="wraper">
	<div class="load">
		<img class="load-bee" src="/assets/repairnew/images/load-bee.png"/>
	</div>
    <div class="top">
        <p>
        	<a href="{BEESCRM::U('repairnew/repairnew/index',array('repairId'=>$repairId))}" class="iconfont icon-zuo fl-left"></a>
        	<span class="fl-left">申请转派</span>
        	<a href="{BEESCRM::U('repairnew/repairnew/index',array('repairId'=>$repairId))}" class="iconfont icon-shouye text-right fl-right"></a>
        </p>
    </div>
    <p class="title">报修编号</p>
    <p class="list" style="margin-bottom: 10px;">{BEESCRM:$orderInfo.order_sn}</p>
	
	        <div class="dialog clearfix">
	            <span class="right-big"></span>
	            <span class="right-middle"></span>
	            
	           <!--  <p><span>到场操作：</span>  {BEESCRM:$repairman['real_name']|mb_substr=0,1,'utf8'}师傅　工号：{BEESCRM:$repairman['number']}</p>
	            <p><span>到场拍照：</span></p> -->

	            <div class="upload-img clearfix">
	                <div class="imgbox fl-left"><span><img style="width:80px;height:80px;"  id="photo"/></span></div>
	                <div class="add-img fl-left" >
	                    <input class="file-input" type="file" accept="image/*" name="upload-file" id="photo_input"/>
	                    <span class="iconfont icon-tianjia tianjia"></span>
	                </div>
	            </div>
	            <p class="form-box">
		                <textarea class="textarea" placeholder="转派原因" id="turn"></textarea>
		            </p>
	           
	            <div class="clearfix">
	                <a href="javascript:void(0)" class="submit" id="changeTurn">申请转派</a>
	               <!--  <a href="javascript:void(0)" class="submit" id="arrive">已到现场</a> -->
	            </div>
	        </div>
</div>

<include file="../commonJS" />
<script type="text/javascript" src="/assets/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.fileupload.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.iframe-transport.js"></script>
<script src="/assets/repairnew/js/fastclick.min.js"></script>
<script>
	$(function(){
		//FastClick.attach(document.body);
		$('#cancel').click(function(){
			$('.layer-wraper').show();
		})

		$('.cancel').click(function(){
			$('.layer-wraper').hide();
		})

		/**
		*申请转派
		*/
		$(document).on('click','#changeTurn',function(){
			var data = {};
			data.order_id = "{BEESCRM:$orderId}";
			data.photo = $('#photo').attr('src');
			data.change_txt = $('#turn').val();
			if(!data.photo){
				$.alert('error','请上传图片');return false;
			}
			if(!data.change_txt){
				$.alert('error','请填写转派原因');return false;
			}
			$.ajax({
				type:'post',
				url:"{BEESCRM::U('repairnew/repairnewReceive/orderChange',array('repairId'=>$repairId))}",
				dataType:'json',
				data:data,
				success:function(res){
					if(res.status=='S'){
						$.alert('success',res.message);
						setTimeout("location.href='/index.php?g=repairnew&m=repairnewReceive&a=index&repairId={BEESCRM:$repairId}&order_id="+data.order_id+"'",2000);
					}else{
						$.alert('error',res.message);
					}
				},
				error:function(){
					$.alert('error','通讯失败，请稍后再试');
				}
			});
		})


		$("#photo_input").fileupload({
			url:"/base/common/upload",//文件上传地址，当然也可以直接写在input的data-url属性内
			done:function(e,result){
				//done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
				//注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
				//返回的数据在result.result中，假设我们服务器返回了一个json对象
				var data=$.parseJSON(result.result);
				if(data.status=='S'){
					$('#photo').attr('src',data.url);
				}else{
					$.alert('error',data.message);
				}
			}
		});
		
		
		

	});

	
    //下面这个函数用来转换数组到json格式
    function arrayToJson(o) {
        var r = [];
        if (typeof o == "string") return "\"" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";
        if (typeof o == "object") {
            if (!o.sort) {
                for (var i in o)
                    r.push(i + ":" + arrayToJson(o[i]));
                if (!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)) {
                    r.push("toString:" + o.toString.toString());
                }
                r = "{" + r.join() + "}";
            } else {
                for (var i = 0; i < o.length; i++) {
                    r.push(arrayToJson(o[i]));
                }
                r = "[" + r.join() + "]";
            }
            return r;
        }
        return o.toString();
    }
    //这个是调用微信图片浏览器的函数
    function imagePreview(curSrc,srcList) {
        //这个检测是否参数为空
        if(!curSrc || !srcList || srcList.length == 0) {
            return;
        }
        //这个使用了微信浏览器提供的JsAPI 调用微信图片浏览器
        WeixinJSBridge.invoke('imagePreview', {
            'current' : curSrc,
            'urls' : srcList
        });
    };

    (function($){
        //下面是获取当前页面所有的img的src 转成数组 并且 转换成json格式
        var aa=[];
        var i=0;
        var src=[];
        var json=null;
        aa=$('img');
        for (i=0;i<aa.length;i++){
            src[i]=aa[i].src;    //把所有的src存到数组里
        }
        var srcList=arrayToJson(src); //转换成json并赋值给srcList
        //下面是点击图片的时候获取当前第几个图片并且启用咱们做的调用微信图片浏览器的函数
        $('img').click(function(){
            var index = $('img').index(this);
            imagePreview(src[index],src);
        });

    })(jQuery);
</script>
</body>

</html>
